const {
	Service
} = require('uni-cloud-router')
const dbUtil = require('db-util')
module.exports = class FileService extends Service {
	constructor(ctx) {
		super(ctx)
	}

	async delete({
		id
	}) {
		let fileObj = await dbUtil.getById({
			collection: 'files',
			id
		})
		if (fileObj) {
			if (fileObj.file.fileID) {
				await uniCloud.deleteFile({
					fileList: [fileObj.file.fileID]
				})
			}
			await dbUtil.removeById({
				collection: 'files',
				id
			})
		}
	}
}
